package presentationTier;

import core.Movie;
import java.util.List;
import javax.swing.table.AbstractTableModel;

/**
 * Datovy model pouziti v jTable1 pro zobrazeni filmu
 * @author vojta
 */
public class MovieTableModel extends AbstractTableModel{

    List<Movie> list = null;

    public MovieTableModel(List<Movie> list) {
        this.list = list;
    }

    public int getRowCount() {
        return list.size();
    }

    public int getColumnCount() {
        return 6;
    }

    @Override
    public String getColumnName(int columnIndex) {
        switch(columnIndex) {
            case 0 : return "Id";
            case 1 : return "Name";
            case 2 : return "Director";
            case 3 : return "Year";
            case 4 : return "Medium";
            //case 5 : return "Medium_id";
            //case 6 : return "Genre_id";
            case 5 : return "Genre";
            default: return "";
        }
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Movie movie = list.get(rowIndex);

        switch (columnIndex) {
            case 0 : return movie.getId();
            case 1 : return movie.getName();
            case 2 : return movie.getDirector();
            case 3 : return movie.getYear();
            //case 4 : return movie.getMedium().getId();
            case 4 : return movie.getMedium().getMedium();
            //case 6 : return movie.getGenre().getId();
            case 5 : return movie.getGenre().getGenre();
            default : return null;
        }
    }

    public Movie getMovieAt(int row) {
        return list.get(row);
    }
    
}